#include"hashcount.h"
#include<stdio.h>

int main(int argc, char* argv[])
{
    class myhashmap A;
    char c;
    FILE* fp;
    int flag = 0;
    char* word = new char;
    if((fp = fopen("alibaba.txt", "r")) == NULL)
    {
        printf("File open error! \n");
        exit(0);
    }
    char* p = word;
    while(!feof(fp))
    {
        c = fgetc(fp);
        //if(c != EOF)
        //{
            
            if(flag == 1)
            {
                if(isabc(c))
                {
                    if(c - 'A' >= 0 && c - 'A' <= 25)
                        c = c + 32;
                    *p = c;
                    p++;
                } 
                else
                {
                    *p = '\0';
                    flag = 0;
                    A.readaword(word);
                }
            }
            else
            {
                if(isabc(c))
                {
                    if(c - 'A' >= 0 && c - 'A' <= 25)
                        c = c + 32;
                    word = new char;
                    p = word;
                    *p = c;
                    flag = 1;
                    p++;
                }
                else
                {
                    continue;
                }
            }
            
        //}
    }
    if(fclose(fp))
    {
        printf("File close error! \n");
        exit(0);
    }
    A.print_most20();
    
   return 0;
}
